import java.util.Scanner;
public class test15_判断质数 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("请输入一个正整数:");
        int num = input.nextInt();
        boolean flag = true;//标记思想,一开始认为是质数,如果有因子就修改成false
        if (num < 2) {
            flag = false;
        } else {
            for (int i = 2; i <= Math.sqrt(num); i++) {
                if (num % i == 0) {
                    flag = false;
                    break;//有因子直接跳出循环
                }
            }
        if (flag) {
            System.out.println(num + "是质数");
        } else {
            System.out.println(num + "不是质数");
        }
        }
        input.close();
    }
}
